#include "../includes/FileApi.h"
#include <sstream>

const int BUFF_SIZE = 10000;

int main(int argc, char* argv[]){
    if(argc != 2){
        std::cout << "Usage : " << argv[0] << " <file path>" << '\n';
        return 0;
    }
    std::string file_path(argv[1]);
    FileApi& file_api = FileApi::getInstance();
    int fd = file_api.open(file_path);
    if(fd == -1){
        std::cout << "Open file error\n";
        return 0;
    }
    char buf[BUFF_SIZE];
    int read_size = file_api.read(fd, buf, BUFF_SIZE);
    if(read_size == -1){
        std::cout << "Read file error\n";
        return 0;
    }
    std::string buf_str(buf, read_size);
    std::istringstream iss(buf_str);
    std::string line;
    while (std::getline(iss, line)) {
        std::cout << line << std::endl;
    }  
    return 0;
}